package rocketmq.test;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;

/**
 * @author: Dragon
 * @since: 2023/12/3 16:40
 */
@Slf4j
public class RocketMQProducer {
    public static void main(String[] args) throws Exception {
        //创建消息生产着
        DefaultMQProducer dragonProducerGroup = new DefaultMQProducer("DragonProducerGroup");
        //设置NameServer地址
        dragonProducerGroup.setNamesrvAddr("127.0.0.1:9876");

        //启动生产者
        dragonProducerGroup.start();

        Message message = new Message("dragonTopic", "dragonTag", "Hello RocketMQ".getBytes());
        System.out.println("生产者发出的消息为：" + JSONObject.toJSONString(message));

        SendResult send = dragonProducerGroup.send(message);

        System.out.println("生产者收到的发送结果信息为：" + JSONObject.toJSONString(send));

        dragonProducerGroup.shutdown();
    }
}
